<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

    public function __construct(){
        parent::__construct();
        //开启session
        $this->load->library('session');
        //获取系统信息
        $this->load->model('system_mdl');
        $this->system_mdl->get_sys();
    }

    public function index(){
        // var_dump(site_url());
        // exit;
        if(empty($_SESSION['user']['id'])){
            $this->login();
        }else{
            redirect(site_url('welcome/index'));
        }
    }

    /**
     * 用户登陆界面
     */
    private function login(){
        if(!empty($_SESSION['user']['id'])){
            redirect(site_url('welcome/index'));
        }

        $this->load->view('login');
    }

    /**
     * 用户登陆验证
     */
    public function login_env(){
        if (!$this->input->is_ajax_request()) {
            show_404();
        }

        $post = $this->input->post();
        if(empty($post['email'])){
            die('登陆邮箱不能为空！');
        }
        if(empty($post['password'])){
            die('登陆密码不能为空！');
        }

        $this->load->model('user_mdl');

        $res = $this->user_mdl->login($post);

        echo $res === false ? '账号或者密码错误' : '1';

    }

}

/* End of file Home.php */
/* Location: ./application/controllers/Home.php */